package com.dylan.job.trigger;

import com.dylan.job.config.JobAdminConfig;
import com.dylan.job.entity.dto.TriggerParam;
import com.dylan.job.entity.po.JobGroup;
import com.dylan.job.entity.po.JobInfo;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class JobTrigger {

    public static void trigger(Integer jobId) {
        //从db中查出任务信息
        JobInfo jobInfo = JobAdminConfig.getConfig().getJobInfoMapper().selectById(jobId);
        if (null == jobInfo) {
            log.error("JobTrigger error The job not found...");
            return;
        }

        //找出group信息
        JobGroup jobGroup = JobAdminConfig.getConfig().getJobGroupMapper().selectById(jobInfo.getJobGroup());

        //初始化触发参数
        TriggerParam  triggerParam=new TriggerParam();
        triggerParam.setExecutorHandler(jobInfo.getExecutorHandler());
        triggerParam.setJobId(jobId);
        triggerParam.setExecutorParams(jobInfo.getExecutorParam());

        //TODO 使用HTTP发起远程调用,并异步等待执行结果

    }
}